package br.com.bacabeleireiros.sysbeleza.dao.impl;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import br.com.bacabeleireiros.sysbeleza.dao.IServicoDAO;
import br.com.bacabeleireiros.sysbeleza.entity.Servico;
import br.com.bacabeleireiros.util.persistence.impl.GenericDAOImpl;

@Repository
public class ServicoDAOImpl extends GenericDAOImpl<Servico, Serializable> implements IServicoDAO, Serializable {

	private static final long serialVersionUID = 1L;
	
	public ServicoDAOImpl() {

	}

	@Override
	public Servico salva(Servico servico) {
		return save(servico);
	}

	@Override
	public Servico getById(Long idServico) {
		return getById(Servico.class, idServico);
	}

	@Override
	public void exclui(Servico servico) {
		remove(servico);
	}

	@Override
	public List<Servico> getAll() {
		return getAll(Servico.class);
	}

	@Override
	public List<Servico> getListaServicoSelecionados(String servicoSelelcionado) {
		String SQL = " from Servico p "
				   + "where (upper(p.descServico) like ? or upper(p.siglaServico) like ?)";
		Query query = em.createQuery(SQL);
		query.setParameter(1, servicoSelelcionado.toUpperCase() + "%");
		query.setParameter(2, servicoSelelcionado.toUpperCase() + "%");
		return query.getResultList();
	}
  
}
